<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<% String Selectlink = (String) session.getAttribute("Selectlink");%>
<title><% out.print(Selectlink);%></title>
<script language="Javascript" type="text/javascript">
var clickstr = null;
function showAlltable() {
	document.getElementById("r1").className = "on";
	document.getElementById("r2").className = "on";
}
function hideAlltable() {
	document.getElementById("r1").className = "off";
	document.getElementById("r2").className = "off";
}
function showtabel(onclick) {
	//將所有食物的tabel設為隱藏
	hideAlltable();
	clickstr = onclick;
	var str = onclick;
	document.getElementById("prints").className = "on";
	document.getElementById(str).className = "on";
}
function printout() {
	if (!window.print){alert("列印功能暫時停用，請按 Ctrl-P 來列印"); return;}
	showAlltable();
	document.getElementById("prints").className = "noprint";
	window.print();
	showtabel(clickstr);
}
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}
</script>
<style type="text/css">
body,td,th {
	color: #000000;
	font-size: 20px;
	font-family: "標楷體";
}

.HEAD_STYLE {
	font-weight: bold;
	color: #437A27;
	font-family: "標楷體";
	font-size: 30px;
}

span {
	color: #000000;
	font-size: 24px;
	font-family: "標楷體";
	font-weight: bold;
}

.button {
	border: 1px;
	padding-top: 4px;
	padding-right: 7px;
	padding-bottom: 4px;
	padding-left: 7px;
	background-color: #468129;
	color: #FFFFFF;
	font-size: 16px;
	border-color: #3C7023;
}

.off {
	display: none
}

.on {
	display: block;
}

.noprint {display:none}
</style>
</head>
<body>
	<div width="80%" align="center">
		<%
			ArrayList<ArrayList<String>> food_NotSuit = (ArrayList<ArrayList<String>>) session
					.getAttribute("food_NotSuit");
		
			ArrayList<ArrayList<String>> food_Suit = (ArrayList<ArrayList<String>>) session
					.getAttribute("food_Suit");
			
			ArrayList<String> foodlist = new ArrayList<String>();
			ArrayList<String> typelist = new ArrayList<String>();
			ArrayList<String> typenamelist = new ArrayList<String>();
			int c = 0;
			String subtypename = "";
		%>

		<span align="center" class="HEAD_STYLE"><% out.print(Selectlink);%></span>
		<hr>
		<div align="center" id="div">
			<a href="javascript:showtabel('r1')">禁忌食物</a> &nbsp; 
			<a href="javascript:showtabel('r2')">可用食物</a> &nbsp; 
		</div>
		<hr>

		<table align="center" class="off" id="r1" border="1">
			<col style="width:40%">
			<tr>
			<td align="left" valign="top">
			<div align=center><span>禁忌食物</span><br></div>
			<%
				typelist = food_NotSuit.get(0);
				foodlist = food_NotSuit.get(1);
				for (int i = 0 ; i < typelist.size() ; i++){
					if (!(typenamelist.contains(typelist.get(i))))
						typenamelist.add(typelist.get(i));
				}
				c = 0;
				while (c < foodlist.size()) {
					if (typenamelist.contains(typelist.get(c))){
						subtypename = typelist.get(c);
						typenamelist.remove(subtypename);
			%>
						<div align="left"><span><%out.print(subtypename);%></span><br></div>
			<% 
					}
					if (typelist.get(c).equals(subtypename)){
						if (c == foodlist.size()-1){
							out.print(foodlist.get(c));
						}else{
							if (typelist.get(c+1).equals(subtypename))
								out.print(foodlist.get(c) + "，");
							else
								out.print(foodlist.get(c) + "<br>");
						}
					}
					c++;
				}
			%>
			</td>
			</tr>
		</table>

		<table align="center" class="off" id="r2" border="1">
			<col style="width:40%">
			<tr>
			<td align="left" valign="top">
			<div align=center><span>可用食物</span><br></div>
			<%
			typelist = food_Suit.get(0);
			foodlist = food_Suit.get(1);
			for (int i = 0 ; i < typelist.size() ; i++){
				if (!(typenamelist.contains(typelist.get(i))))
					typenamelist.add(typelist.get(i));
			}
			c = 0;
			while (c < foodlist.size()) {
				if (typenamelist.contains(typelist.get(c))){
					subtypename = typelist.get(c);
					typenamelist.remove(subtypename);
			%>
					<div align=left><span><%out.print(subtypename);%></span><br></div>
			<% 
				}
				if (typelist.get(c).equals(subtypename)){
					if (c == foodlist.size()-1){
						out.print(foodlist.get(c));
					}else{
						if (typelist.get(c+1).equals(subtypename))
							out.print(foodlist.get(c) + "，");
						else
							out.print(foodlist.get(c) + "<br>");
					}
				}
				c++;
			}
			%>
			</td>
			</tr>
		</table>
		<a id="prints" href="javascript:printout()">列印本頁</a>
	</div>
</body>
</html>